const app = getApp();
Page({
  data: {
    purchaseStatus: "",
    tasteScore: null,
    preorderScore: null,
    discountScore: null,
    discountSuggestion: '',
    merchantSuggestion: '',
    isCommit:true
  },
  handlePurchaseAnswer: function (e) {
    this.setData({
      purchaseStatus: e.detail.value
    });
  },
  handleTasteScore: function (e) {
    this.setData({
      tasteScore: e.detail.value
    });
  },
  handlePreorderScore: function (e) {
    this.setData({
      preorderScore: e.detail.value
    });
  },
  handleDiscountScore: function (e) {
    this.setData({
      discountScore: e.detail.value
    });
  },
  handleDiscountSuggestion: function (e) {
    this.setData({
      discountSuggestion: e.detail.value
    });
  },
  handleMerchantSuggestion: function (e) {
    this.setData({
      merchantSuggestion: e.detail.value
    });
  },
  submitSurvey: function () {
    const { preorderScore, discountScore, merchantSuggestion } = this.data;
    // 在这里可以将数据发送到服务器，或者进行本地存储等操作
    console.log(JSON.stringify(this.data))
    // 可添加向服务器发送数据的代码，如使用wx.request等
    app.wxRequest('POST', '/surveyResult/save',this.data, (res) => { 
      if(200==res.code){ 
        
        this.setData({ 
         isCommit:false
        }) 
      } else{
        console.log(res.msg) 
        app.showMsg(res.msg);
      }
    }, (err) => { 
      app.showMsg(err.errMsg);
      console.log(err.errMsg) 
    }) 
  },
/**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      console.log("110110110")
      app.checkIsLogin();
  }
});